<?php
/**
 * Created by PhpStorm.
 * User: dy
 * Date: 2020/1/7
 * Time: 14:08
 */
namespace app\admin\model;
use app\common\model\BaseModel;
use think\Request;
use util\ConfigUtil;

class Config extends BaseModel
{
    public function getTypeTextAttr($value,$data){
        $config_type_list  = ConfigUtil::instance()->parse_config_array(config('config.config_type_list'));
        return $config_type_list[$data['type']];
    }
    public function getGroupTextAttr($value,$data){
        $config_group_list  = ConfigUtil::instance()->parse_config_array(config('config.config_group_list'));
        return isset($config_group_list[$data['group']]) ? $config_group_list[$data['group']] : '不分组';
    }
    public function buildParams(Request $request){
        $where = [];
        $page = $request->get('page',DATA_NORMAL);
        $limit = $request->get('limit',LIMIT);
        $order = $request->get('order','ASC');
        $sort = $request->get('sort','sort');
        $group = $request->get('group');
        if($group){
            $where[] = ['group','=',$group];
        }
        return [$where,$sort,$order,$page,$limit];
    }
}